
package com.sttk.fastMark.camera.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lxj.xpopup.core.AttachPopupView;
import com.sttk.fastMark.camera.R;
import com.sttk.fastMark.camera.adapter.DelayAdapter;
import com.sttk.fastMark.camera.bean.DelayBean;

import java.util.ArrayList;
import java.util.List;

public class DelayDialog extends AttachPopupView implements View.OnClickListener {

    private RecyclerView recyclerView;
    private DelayAdapter delayAdapter;

    public DelayDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_scale_style;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        recyclerView = findViewById(R.id.rvScaleList);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        delayAdapter = new DelayAdapter();
        recyclerView.setAdapter(delayAdapter);
        delayAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                if (listener != null) {
                    dismiss();
                    listener.click(delayAdapter.getItem(position));
                }
            }
        });
        List<DelayBean> list = new ArrayList<>();
        list.add(new DelayBean(R.drawable.adjs, 0));
        list.add(new DelayBean(R.drawable.ays5s, 1));
        list.add(new DelayBean(R.drawable.ays10s, 2));
        delayAdapter.setList(list);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void click(DelayBean delayBean);
    }

}
